/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package yoga.algo.process;

import yoga.algo.coding.ICoding;
import yoga.algo.coding.IGenotypeCodec;
import yoga.algo.phenotype.Individual;
import yoga.probability.Probablistics;

public class SimpleReproductionMethod<T> implements IReproducionMethod<T>
{
    @Override
    public Individual<T> reproduceChild(Individual<T> parnet1, Individual<T> parent2)
    {
        ICoding<T> coding1 = parnet1.getCoding().getCopy();
        ICoding<T> coding2 = parent2.getCoding().getCopy();

        IGenotypeCodec<T> codec = parnet1.getGenotypeCodec();
        Individual<T> child;

        if (Probablistics.randomBoolean(0.7))
        {
            coding1.crossWith(ICoding.CrossingTypes.Single, coding2);
        }
        
        if (Probablistics.randomBoolean(0.5))
        {
            child = new Individual<T>(coding1, codec);
        }
        else
        {
            child = new Individual<T>(coding2, codec);
        }

        return child;
    }
}
